using CodeAgent.Host.Options;
using CodeAgent.Host.Service;
using Microsoft.AspNetCore.WebSockets;

var builder = WebApplication.CreateBuilder(args);


builder.Services
    .AddCors(options =>
    {
        options.AddPolicy("AllowAll",
            builder => builder
                .SetIsOriginAllowed(_ => true)
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials());
    });


builder.Configuration.GetSection(DockerOptions.Name)
    .Get<DockerOptions>();

builder.Services.AddWebSockets((options =>
{
    options.KeepAliveTimeout = TimeSpan.FromSeconds(120);
    options.KeepAliveInterval = TimeSpan.FromSeconds(60);
}));
builder.Services.AddSignalR();

builder.Services.AddHttpContextAccessor();

var app = builder.Build();

app.UseCors("AllowAll");
app.UseWebSockets((new WebSocketOptions()
{
    KeepAliveInterval = TimeSpan.FromSeconds(120),
}));

app.UseStaticFiles();

app.MapHub<CodeAgentHub>("/api/Agent", (options =>
{
    
}));


await app.RunAsync();